﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>招聘职位管理</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <script src="/scripts/boot.js" type="text/javascript"></script>
    <style type="text/css">
        .mini-summary-row
        {
            background-color: #FFFFE6;
        }
        html, body
        {
            margin: 0;
            padding: 0;
            border: 0;
            width: 100%;
            height: 100%;
            overflow: hidden;
        }
    </style>
</head>
<body>
    <div style="width: 100%;" runat="server" id="operationPanel">
        <div class="mini-toolbar" style="border-bottom: 0; padding: 0px;">
            <table style="width: 100%;">
                <tr>
                    <td style="width: 100%;">
                        <a class="mini-button" iconcls="icon-add" onclick="addRow()" plain="true" runat="server"
                            id="btnAdd">增加</a> <a class="mini-button" iconcls="icon-upload" onclick="showImport()"
                                plain="true" runat="server" id="btnImport">导入</a><span class="separator"></span><a
                                    class="mini-button" iconcls="icon-remove" runat="server" id="btnDelete" onclick="deleteRows()"
                                    plain="true">删除</a><span class="separator"></span> <a class="mini-button" iconcls="icon-ok"
                                        runat="server" id="btnPublish" onclick="publish(true)" plain="true">发布</a><a class="mini-button"
                                            iconcls="icon-undo" runat="server" id="btnCancel" onclick="publish(false)" plain="true">取消</a>
                    </td>
                    <td style="white-space: nowrap;">
                        <input id="key" class="mini-textbox" emptytext="请输入关键字" style="width: 280px;" onenter="onKeyEnter" />
                        <a class="mini-button" onclick="search()" iconcls="icon-search"></a>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <div class="mini-fit">
        <div id="datagrid1" class="mini-datagrid" style="width: 100%; height: 100%;" allowresize="true"
            pagesize="20" allowcellselect="true" multiselect="true" allowcelledit="false"
            oncellendedit="cellendedit" allowcellvalid="true" editnextonenterkey="true" editnextrowcell="true"
            url="/Handler.ashx?method=LoadClient" idfield="ID">
            <div property="columns">
                <div type="indexcolumn" headeralign="center" allowsort="true">
                    序号</div>
                <div type="checkcolumn">
                </div>
                <div name="Name" field="Name" headeralign="center" allowsort="true" width="200">
                    名称
                </div>
                <div name="IP" field="IP" headeralign="center" allowsort="true" width="150">
                    IP
                </div>
                <div name="Status" field="Status" headeralign="center" allowsort="false" width="80">
                    状态
                </div>
                <div name="Info" field="Info" headeralign="center" allowsort="false" width="100%">
                    详情
                </div>
                <div name="edit" width="150" align="center" headeralign="center">
                    操作
                </div>
            </div>
        </div>
    </div>
    <div id="win" class="mini-window" title="导入" style="width: 480px; height: 200px"
        showmaxbutton="false" showmodal="true" allowresize="false" bodystyle="overflow:hidden;">
        <table width="100%" height="100%">
            <tr>
                <td align="left" width="200px" colspan="2">
                    <form id="fileUploadForm" method="post" enctype="multipart/form-data" target="frame0"
                    action="/en/Handler.ashx?method=ImportRecruitment&callback=window.parent.importCallback">
                    <input id="importFile" name="importFile" type="file" style="width: 100%" />
                    </form>
                </td>
            </tr>
            <tr>
                <td align="right">
                    <a href="/data/RecruitmentTemplate.xls">下载导入模板
                </td>
                <td align="right" width="100px">
                    <span type="button" class="mini-button" iconcls="icon-ok" width="90px" text="确定"
                        onclick="importData();" /><span type="button" class="mini-button" iconcls="icon-cancel"
                            width="90px" text="取消" onclick="hideImport();" />
                </td>
            </tr>
        </table>
    </div>
    <iframe id="frame0" name="frame0" style="display: none"></iframe>
    <script type="text/javascript">
        mini.parse();
        var grid = mini.get("datagrid1");
        grid.on("drawcell", function (e) {
            var column = e.column;
            if (column.name == "edit") {
                e.cellHtml = ""; e.cellStyle = "text-align:center";
                e.cellHtml += '<a href="javascript:openEditPage(' + e.rowIndex + ')">分配</a>&nbsp;&nbsp;&nbsp;&nbsp;';
                e.cellHtml += '<a href="javascript:reboot(' + e.rowIndex + ')">重启</a>&nbsp;&nbsp;&nbsp;&nbsp;';
                e.cellHtml += '<a href="javascript:openEditPage(' + e.rowIndex + ')">退出</a>&nbsp;&nbsp;&nbsp;&nbsp;';
            } else if (column.field == "Status" && e.record.Status =="等待") {
                e.cellStyle = "background:lightgreen;";
            }
        });

        grid.sortBy("Order", "asc");
        grid.load();

        function search() {
            var key = mini.get("key").getValue(); grid.load({
                key: key
            });z
        }

        function onKeyEnter(e) { search(); }

        function addRow() {
            mini.open({
                url: "/en/hr/RecruitmentForm.aspx?mode=add", title: "新增数据", iconCls: "icon-title-add",
                width: 908, height: 577,
                onload: function () { },
                ondestroy: function (action) {
                    if (action == "changed") { grid.reload(); }
                }
            });
        }
        function deleteRow(rowIndex) {
            var array = new Array(); var rowData = grid.getRow(rowIndex); array.push(rowData.ID);
            delStory(array);
        }

        function deleteRows() {
            var array = new Array();
            var datas = grid.getSelecteds();
            if (1 > datas.length) { $.notify("请选择要删除的行记录"); return; }
            for (var i = 0; i < datas.length; i++) { array.push(datas[i].ID); } delStory(array);
        }

        function delStory(ids) {
            $.confirm("确定删除吗？", function (action) {
                if ('是' != action) { return; }
                mask();
                $.ajax({ url: "/en/Handler.ashx?method=DelRecruitment",
                    data: { data: mini.encode(ids) },
                    type: "post",
                    success: function (text) {
                        var result = mini.decode(text);
                        if (result.Success) { grid.reload(); }
                        else {
                            $.alert("操作失败" + result.Message);
                        }
                        unmask();
                    }, error: function (jqXHR, textStatus, errorThrown)
                    { $.alert(jqXHR.responseText); unmask(); }
                });
            });
        }
        function reboot(index) {
            var id = grid.getRow(index).ID;
            mask();
            $.ajax({ url: "/Handler.ashx?method=Reboot&id="+id,
                type: "post",
                success: function (text) {
                    var result = mini.decode(text);
                    if (result.Success) { grid.reload(); }
                    else {
                        $.alert("操作失败！");
                    }
                    unmask();
                }, error: function (jqXHR, textStatus, errorThrown)
                { $.alert(jqXHR.responseText); unmask(); }
            });
        }
        function openEditPage(rowIndex) {
            mini.open({ url: "/en/hr/RecruitmentForm.aspx?mode=edit&id=" + grid.getRow(rowIndex).ID,
                title: "编辑数据",
                iconCls: "icon-title-edit",
                width: 908,
                height: 610,
                ondestroy: function (action) { if (action == "changed") { grid.reload(); } }
            });
        }

        function publishRow(rowIndex, published) {
            var array = new Array();
            array.push(grid.getRow(rowIndex).ID);
            submitData(array, published);
        }

        function publish(published) {
            var array = new Array();
            var datas = grid.getSelecteds();
            for (var i = 0; i < datas.length; i++) {
                array.push(datas[i].ID);
            } submitData(array, published);
        }

        function submitData(ids, published) {
            if (ids.length == 0) { $.alert("没有需要发布的数据！"); return; }
            grid.loading("");
            $.ajax({ url: "/en/Handler.ashx?method=PublishRecruitment&publish=" + (published ? "true" : ""),
                data: { data: mini.encode(ids) },
                type: "post",
                success: function (text) {
                    var result = mini.decode(text); if (result.Success) {
                        grid.reload();
                        if (result.Message) { $.alert(result.Message); }
                    } else {
                        grid.unmask(); $.alert("审批失败：" + result.Message)
                    }
                }, error: function (jqXhr) {
                    $.alert(jqXhr.responseText); grid.unmask();
                }
            });
        }

        function showImport() { var win = mini.get("win"); win.show(); }
        function hideImport() { var win = mini.get("win"); win.hide(); }
        function importData() {
            if ($("#importFile").val() == "") { return; } mask(); $("#fileUploadForm").submit();
        }
        function importCallback(result) {
            if (result.Success) {
                $.notify("操作成功"); $("#importFile").val("");
                hideImport(); grid.reload();
            } else { $.alert("操作失败"); } unmask();
        } </script>
</body>
</html>
